package com.example.user.concurrent;

import com.example.user.UserMain;
import com.example.user.bo.Person01BO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

//测试用例
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { ThreadTest01.class, UserMain.class})
public class ThreadTest01 {

    @Autowired
    ConcurrentService concurrentService;
    /**
     *   测试多线程事务.
     * @throws InterruptedException
     */
    @Test
    public  void test() throws InterruptedException {
        int size = 10;
        List<Person01BO> list = ConcurrentService.getTestDate();

        try {
            //事务不统一
            concurrentService.saveThread(list);
            System.out.println("添加成功");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    @Test
    public  void test2() throws InterruptedException {
        int size = 10;
        List<Person01BO> list = ConcurrentService.getTestDate();

        try {
            //事务统一
            concurrentService.saveThread2(list);
            System.out.println("添加成功");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}